<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div>
    <h1>商品列表</h1>
    <table border="1">
        <tr>
            <th>id</th>
            <th>商品标题</th>
            <th>价格</th>
            <th>库存</th>
            <th>操作</th>
        </tr>

        <tr v-for="a in arr">
            <td>{{a.id}}</td>
            <td>{{a.title}}</td>
            <td>{{a.price}}</td>
            <td>{{a.num}}</td>
            <td><a href="javascript:void(0)" @click="del(a.id)">删除</a>
            <a :href="'/update.html?id='+a.id">修改</a>
            <a href="/insert.html">添加</a></td></td>
        </tr>
    </table>
</div>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
   <script src=" https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
     <script>
       let v=new Vue({
         el:"body>div",
         data:{
             arr:[{id:1,title:"苹果",price:5,num:100},
                 {id:2,title:"香蕉",price:6,num:10}
             ,{id:3,title:"橘子",price:4,num:170}]
         },
         methods:{
             del(id) {
                 if (confirm("确定删除")){
                     axios.get("/delete?id=" + id).then(function (response) {
                         location.reload();
                     })
             }
             }
         },
           created:function (){
             //created方法是vue对象的内置方法
               console.log("执行")
               axios.get("/select").then(function (response) {
                   v.arr=response.data;
               })
           }
       })

     </script>
</body>
</html>